package com.dwd.user.controller;

import com.dwd.basic.utils.AjaxResult;
import com.dwd.org.pojo.Employee;
import com.dwd.user.mapper.LoginInfoMapper;
import com.dwd.user.pojo.LoginInfo;
import com.dwd.user.pojo.User;
import com.dwd.user.pojo.dto.LoginInfoDto;
import com.dwd.user.service.ILoginInfoService;
import com.dwd.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/1/16 12:33
 * @Version 1.0
 */
@RestController
public class LoginInfoController {


    @Autowired
    private ILoginInfoService loginInfoService;

    /**
     * 登陆
     *
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            return loginInfoService.login(loginInfoDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 验证码登陆
     *
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/loginVer")
    public AjaxResult loginVer(@RequestBody LoginInfoDto loginInfoDto) {
        try {

            Map<String, Object> map = loginInfoService.loginVer(loginInfoDto);
            return AjaxResult.me().setResultObj(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 找回密码之手机验证码
     *
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/forget")
    public AjaxResult forget(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            return loginInfoService.forget(loginInfoDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    @PostMapping("/forgetEmail")
    public AjaxResult forgetEmail(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            return loginInfoService.forgetEmail(loginInfoDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 找回密码之密码存储
     *
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/found")
    public AjaxResult found(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            loginInfoService.found(loginInfoDto);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 失去焦点校验密码
     *
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/checkPassword")
    public AjaxResult checkPassword(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            loginInfoService.checkPassword(loginInfoDto);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 失去焦点校验重复密码
     * @param loginInfoDto
     * @return
     */
    @PostMapping("/checkConfirmpassword")
    public AjaxResult checkConfirmpassword(@RequestBody LoginInfoDto loginInfoDto) {
        try {
            loginInfoService.checkConfirmpassword(loginInfoDto);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }


}
